<?php

namespace catchAdmin\disease\controller;

use catcher\base\CatchRequest;
use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use catchAdmin\disease\model\DiseaseTemplate as DiseaseTemplateModel;
use think\Response;

class DiseaseTemplate extends CatchController
{
    protected $diseaseTemplateModel;

    /**
     *
     * @time 2023/12/20 19:04
     * @param DiseaseTemplateModel $diseaseTemplateModel
     * @return mixed
     */
    public function __construct(DiseaseTemplateModel $diseaseTemplateModel)
    {
        $this->diseaseTemplateModel = $diseaseTemplateModel;
    }

    /**
     *
     * @time 2023/12/20 19:04
     * @return Response
     */
    public function index(CatchRequest $request): Response
    {
        $userId = $request->user()->id;
        $type = $request->param('type', 0, "int");
        $result = $this->diseaseTemplateModel->getLists($userId, $type);

        return CatchResponse::paginate($result);
    }

    /**
     *
     * @time 2023/12/20 19:04
     * @param Request $request
     * @return Response
     */
    public function save(CatchRequest $request): Response
    {

        return CatchResponse::success($this->diseaseTemplateModel->createBy($request->param()));
    }

    /**
     *
     * @time 2023/12/20 19:04
     * @param $id
     * @return Response
     */
    public function read($id): Response
    {
        return CatchResponse::success($this->diseaseTemplateModel->findBy($id));
    }

    /**
     *
     * @time 2023/12/20 19:04
     * @param $id
     * @param Request $request
     * @return Response
     */
    public function update($id, Request $request): Response
    {
        return CatchResponse::success($this->diseaseTemplateModel->updateBy($id, $request->post()));
    }

    /**
     *
     * @time 2023/12/20 19:04
     * @param $id
     * @return Response
     */
    public function delete($id): Response
    {
        return CatchResponse::success($this->diseaseTemplateModel->deleteBy($id));
    }
}